package com.cy.personer.biz.impl;

import com.cy.personer.bean.Advert;
import com.cy.personer.biz.AdvertBiz;
import com.cy.personer.ceptor.OperationLog;
import com.cy.personer.mapper.AdvertMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

//广告
@Service
public class AdvertBizImpl implements AdvertBiz {

    @Resource
    AdvertMapper advertMapper;

    /**
     * 新增广告
     * @param advert
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="添加",methods = "添加新广告" )
    @Override
    public boolean addAdvert(Advert advert) {
        return advertMapper.addAdvert(advert)>0;
    }

    /**
     * 修改广告
     * @param advert
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="修改",methods = "修改广告" )
    @Override
    public boolean updateAdvert(Advert advert) {
        return advertMapper.updateAdvert(advert)>0;
    }

    /**
     * 获得广告列表
     * @param advert
     * @param pageNum
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="查询",methods = "查看所有广告" )
    @Override
    public PageInfo<Advert> getAdverts(Advert advert, int pageNum) {
        Page<Advert> page = PageHelper.startPage(pageNum,5);
        advertMapper.getAdverts(advert);
        PageInfo<Advert> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    /**
     * 获取广告详情
     * @param advert
     * @return
     * @author 林少艺
     */
    @Override
    public Advert getAdvert(Advert advert) {
        return advertMapper.getAdvert(advert);
    }

    /**
     * 删除广告
     * @param advert
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="删除",methods = "删除了广告" )
    @Override
    public boolean delAdvert(Advert advert) {
        return advertMapper.delAdvert(advert)>0;
    }


    //显示广告 WHL
    @Override
    public List<Advert> quers() {
        return advertMapper.quers();
    }


}
